package com.gitee.swsk33.mybatisdemo;

import com.gitee.swsk33.mybatisdemo.config.MySessionFactory;
import com.gitee.swsk33.mybatisdemo.dao.CharacterDAO;
import com.gitee.swsk33.mybatisdemo.dataobject.Character;
import org.apache.ibatis.session.SqlSession;

public class Main {

	private static CharacterDAO characterDAO;

	public static void main(String[] args) {
		// 先初始化工厂
		MySessionFactory.createSqlSessionFactory();
		// 创建一个SqlSession对象表示当前会话
		SqlSession session = MySessionFactory.getSqlSessionFactory().openSession();
		// 用SqlSession对象获取Mapper（DAO）接口
		characterDAO = session.getMapper(CharacterDAO.class);
		// 执行DAO中的方法就行了！
		Character getChar = characterDAO.getById(2);
		System.out.println(getChar.getId() + " " + getChar.getName() + " " + getChar.getNickname() + " " + getChar.getType() + " " + getChar.getGuild());
		// 最后记得关闭会话
		session.close();
	}

}